package com.spring.security.core.annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;

import com.spring.nbrbt.tools.otherutil.ValidatorResultHandler;
import com.spring.security.web.model.BaseResult;

@Aspect
@Component
public class SpringCheckParamterValidity {
	@Pointcut("@annotation(com.spring.security.core.annotation.CheckParamterValidity)")
	public void checkParamterValidity(){
	}
	
	@Around("checkParamterValidity()")
	public Object aroundExec(ProceedingJoinPoint pjp) throws Throwable{
		Object[] parameters=pjp.getArgs();
		for(int i=0;i<parameters.length;i++){
			Object parameter=parameters[i];
			if(parameter instanceof BindingResult){
				BaseResult checkResult = ValidatorResultHandler.handleResult((BindingResult)parameter);
				if(checkResult.getStatus().equals("0")){
					return checkResult;
				}
			}
		}
		return pjp.proceed();
	}
	
}
